﻿import kliment.display.MCC;
import kliment.geom.SimplePoint;

/**
 * ...
 * @author	Kliment
 * @version	1.4.3
 */
class kliment.display.Sprite {
	private var _CLASS_NAME:String = 'Sprite';
	private var _target_mc:MovieClip;
	private var _mask_mc:MovieClip;
	
	public function Sprite(target_mc:MovieClip, isParent:Boolean) {
		_target_mc = (isParent)?MCC.create(target_mc):target_mc;
		
	}
	
	public function startDrag(lockCenter:Boolean, left:Number, top:Number, right:Number, bottom:Number):Void {
		_target_mc.startDrag(lockCenter, left, top, right, bottom);
	}
	
	public function stopDrag(lockCenter:Boolean, left:Number, top:Number, right:Number, bottom:Number):Void {
		_target_mc.stopDrag();
	}
	
	public function get x():Number {return _target_mc._x }
	public function set x(value:Number):Void { _target_mc._x = value }
	
	public function get y():Number {return _target_mc._y }
	public function set y(value:Number):Void { _target_mc._y = value }
	
	public function get width():Number {return _target_mc._width }
	public function set width(value:Number):Void { _target_mc._width = value }
	
	public function get height():Number {return _target_mc._height }
	public function set height(value:Number):Void { _target_mc._height = value }
	
	public function get visible():Boolean {return _target_mc._visible }
	public function set visible(value:Boolean):Void { _target_mc._visible = value }
	
	public function addChild():Sprite {
		return new Sprite(_target_mc, true);
	}
	
	public function swapDepths(num:Number):Void {
		_target_mc.swapDepths(num);
	}
	
	public function swapDepthTop():Number {
		return MCC.swapDepthsTop(_target_mc)
	}
	
	public function setMask(mask_mc:MovieClip):Boolean {
		if (_target_mc._parent == mask_mc._parent) {
			_target_mc.setMask(mask_mc);
			_mask_mc = mask_mc;
			return true;
		}
		return false;
	}
	
	public function getPositionIn(target_mc:MovieClip):SimplePoint {
		return MCC.translatePosition(_target_mc, target_mc);
	}
	
	public function translateTo(p:Object):Void {
		_target_mc._x = p.x;
		_target_mc._y = p.y;
	}
	
	public function get target_mc():MovieClip { return _target_mc }
	
	public function get mask_mc():MovieClip { return _mask_mc }
	public function set mask_mc(mc:MovieClip):Void {
		setMask(mc);
	}
	
	public function toString(fullPathTarget:Boolean):String {
		var str:String = _CLASS_NAME + ' target:';
		if (fullPathTarget)
			str += String(_target_mc);
		else 
			str += _target_mc._name;
		return '[' + str + ']';
	}
	
	public function remove():Void {
		MCC.remove(_target_mc);
		delete this;
	}
}